package com.fengjing.launcher.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v17.leanback.widget.VerticalGridView;
import android.util.Log;
import android.widget.Toast;

import com.fengjing.launcher.R;
import com.fengjing.launcher.common.MyAdapter;
import com.fengjing.launcher.model.FilmModel;
import com.fengjing.launcher.parse.FilmParser;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2017/9/21.
 */

public class ListActivity extends BaseActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);

        VerticalGridView gridView = (VerticalGridView) findViewById(R.id.grid_view);
        gridView.setNumColumns(5);
        MyAdapter myAdapter = new MyAdapter();
        myAdapter.setChildMarginTop(150);
        myAdapter.setChildMarginBottom(300);
        myAdapter.setNumColumns(5);
        List<FilmModel> filmModels = new ArrayList<>();

        try {
            FilmParser.getFilmList(getIntent().getStringExtra("rootPath"),filmModels);

            myAdapter.setFilmModels(filmModels);
            gridView.setAdapter(myAdapter);
        }catch (Exception e){
            Toast.makeText(this, "数据获取失败", Toast.LENGTH_SHORT).show();
            finish();
        }

    }
}
